package commands;

import indexes.BattingIndex;
import indexes.PlayerIDIndex;
import indexes.PlayerNameIndex;

import java.io.IOException;
import java.util.List;

import util.BattingDatabaseFile;
import util.DatabaseFile;
import util.PlayerLogger;
/**
 * Shows the batting details for each
 * record in the database for the given ID.
 * @author xclite
 *
 */
public class ShowBattingDetailsCommand extends Command
{
    /**
     * Typical constructor.
     * @param arguments
     */
    protected ShowBattingDetailsCommand( List<String> arguments )
    {
        super( arguments );
    }

    @Override
    public boolean execute(
        PlayerIDIndex idIndex,
        PlayerNameIndex nameIndex,
        PlayerLogger logger,
        DatabaseFile database, BattingIndex battingIndex, BattingDatabaseFile battingDatabase ) throws IOException
    {
        logger.write(super.getDivider() + "\n");
        logger.write("Command: show__batting_details_for " + getArguments().get(0) + "\n\n");
        Long foundOffset = battingIndex.search(getArguments().get(0));
        
        if (foundOffset != null)
        {
            logger.write("Batting details for " + getArguments().get(0) + " should be at offset " +
                foundOffset + "\n");
            logger.write(battingDatabase.getBattingDetails(foundOffset) + "\n");
        }
        else
        {
            logger.write("Id: " + getArguments().get(0) + "not found.\n");
        }
        return true;
    }
}